﻿using System;
using System.ComponentModel.DataAnnotations;
using XRM.Security.DataAccess.Enums;
using XRM.Security.DataAccess.Helpers;
using db = XRM.Security.DataAccess.Models;

namespace XRM.Security.WebUI.Models.IdentityCenter
{
    public class IdentityCenterFileModel : BaseViewModel
    {
        public IdentityCenterFileModel()
        {
        }

        public IdentityCenterFileModel(db.IdentityCenterCert dbEntity)
        {
            if (dbEntity != null)
            {
                Id = dbEntity.IdentityCenterCertId;
                FileName = dbEntity.FileName;
                UploadDate = dbEntity.UploadDate;
                FromDate = dbEntity.FromDate;
                ToDate = dbEntity.ToDate;
                Status = dbEntity.Status();
                SerialNumber = dbEntity.SerialNumber;
            }
        }


        [Display(Name = "Сертификаты")]
        [Required(ErrorMessage = "Поле 'Сертификат' обязательное")]
        [MaxLength(255, ErrorMessage = "Максимальная длина поля 'Сертификат' 255 символов")]
        public string FileName { get; set; }

        public string SerialNumber { get; set; }

        [Display(Name = "Дата загрузки")]
        public DateTime UploadDate { get; set; }

        public DateTime FromDate { get; set; }
        public DateTime ToDate { get; set; }
        public CertStatus Status { get; set; }

        public string ValidPeriod 
        {
            get
            {
                return FromDate.ToString("dd.MM.yyyy") + " - " + ToDate.ToString("dd.MM.yyyy");
            }
        }
        public string StatusCaption
        {
            get
            {
                return Status.Description();
            }
        }

    }
}